<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII" />
<title>
  File: README
  
    &mdash; Documentation by YARD 0.8.4.1
  
</title>

  <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />

  <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  hasFrames = window.top.frames.main ? true : false;
  relpath = '';
  framesUrl = "frames.html#!" + escape(window.location.href);
</script>


  <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="js/app.js"></script>


  </head>
  <body>
    <div id="header">
      <div id="menu">
  
    <a href="_index.html">Index</a> &raquo; 
    <span class="title">File: README</span>
  

  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">
  
    <a class="full_list_link" id="class_list_link"
        href="class_list.html">
      Class List
    </a>
  
    <a class="full_list_link" id="method_list_link"
        href="method_list.html">
      Method List
    </a>
  
    <a class="full_list_link" id="file_list_link"
        href="file_list.html">
      File List
    </a>
  
</div>
      <div class="clear"></div>
    </div>

    <iframe id="search_frame"></iframe>

    <div id="content"><div id='filecontents'><h1>README</h1>

<h2>Summary</h2>

<p>Helpful functionality for sorting and comparing.</p>

<h2>Installation</h2>

<p><code>gem install sorting</code></p>

<h2>Usage</h2>

<p>Sort a list of Person objects</p>

<pre class="code ruby"><code class="ruby"><span class='comment'># Convenient
</span><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>sorting/convenience</span><span class='tstring_end'>'</span></span>
<span class='id identifier rubyid_people'>people</span><span class='period'>.</span><span class='id identifier rubyid_sort_by'>sort_by</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_person'>person</span><span class='op'>|</span> <span class='lbracket'>[</span><span class='id identifier rubyid_asc'>asc</span><span class='lparen'>(</span><span class='id identifier rubyid_person'>person</span><span class='period'>.</span><span class='id identifier rubyid_first_name'>first_name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_asc'>asc</span><span class='lparen'>(</span><span class='id identifier rubyid_person'>person</span><span class='period'>.</span><span class='id identifier rubyid_last_name'>last_name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_desc'>desc</span><span class='lparen'>(</span><span class='id identifier rubyid_person'>person</span><span class='period'>.</span><span class='id identifier rubyid_age'>age</span><span class='rparen'>)</span><span class='rbracket'>]</span> <span class='rbrace'>}</span>

<span class='comment'># Or without patching Kernel
</span><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>sorting</span><span class='tstring_end'>'</span></span>
<span class='id identifier rubyid_people'>people</span><span class='period'>.</span><span class='id identifier rubyid_sort_by'>sort_by</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_person'>person</span><span class='op'>|</span>
  <span class='lbracket'>[</span><span class='const'>Sorting</span><span class='period'>.</span><span class='id identifier rubyid_asc'>asc</span><span class='lparen'>(</span><span class='id identifier rubyid_person'>person</span><span class='period'>.</span><span class='id identifier rubyid_first_name'>first_name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='const'>Sorting</span><span class='period'>.</span><span class='id identifier rubyid_asc'>asc</span><span class='lparen'>(</span><span class='id identifier rubyid_person'>person</span><span class='period'>.</span><span class='id identifier rubyid_last_name'>last_name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='const'>Sorting</span><span class='period'>.</span><span class='id identifier rubyid_desc'>desc</span><span class='lparen'>(</span><span class='id identifier rubyid_person'>person</span><span class='period'>.</span><span class='id identifier rubyid_age'>age</span><span class='rparen'>)</span><span class='rbracket'>]</span>
<span class='rbrace'>}</span>

<span class='comment'># Care about expensive comparison values which may not always be needed
</span><span class='comment'># assume item.expensive_value takes a lot of time to compute, but since it's the second value,
</span><span class='comment'># it might only be needed in a small number of cases.
</span><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>sorting/convenience</span><span class='tstring_end'>'</span></span>
<span class='id identifier rubyid_items'>items</span><span class='period'>.</span><span class='id identifier rubyid_sort_by'>sort_by</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_item'>item</span><span class='op'>|</span>
  <span class='lbracket'>[</span><span class='id identifier rubyid_asc'>asc</span><span class='lparen'>(</span><span class='id identifier rubyid_item'>item</span><span class='period'>.</span><span class='id identifier rubyid_cheap_value'>cheap_value</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_asc'>asc</span><span class='lparen'>(</span><span class='symbol'>:nils_last</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_item'>item</span><span class='period'>.</span><span class='id identifier rubyid_expensive_value'>expensive_value</span> <span class='rbrace'>}</span><span class='rbracket'>]</span>
<span class='rbrace'>}</span>

<span class='comment'># Care about nil values in your data
</span><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>sorting/convenience</span><span class='tstring_end'>'</span></span>
<span class='id identifier rubyid_people'>people</span><span class='period'>.</span><span class='id identifier rubyid_sort_by'>sort_by</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_person'>person</span><span class='op'>|</span>
  <span class='lbracket'>[</span><span class='id identifier rubyid_asc'>asc</span><span class='lparen'>(</span><span class='id identifier rubyid_person'>person</span><span class='period'>.</span><span class='id identifier rubyid_first_name'>first_name</span><span class='comma'>,</span> <span class='symbol'>:nils_first</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_asc'>asc</span><span class='lparen'>(</span><span class='id identifier rubyid_person'>person</span><span class='period'>.</span><span class='id identifier rubyid_first_name'>first_name</span><span class='comma'>,</span> <span class='symbol'>:nils_last</span><span class='rparen'>)</span><span class='rbracket'>]</span>
<span class='rbrace'>}</span>

<span class='comment'># Only care about nil values in your data
</span><span class='lbracket'>[</span><span class='int'>5</span><span class='comma'>,</span><span class='int'>3</span><span class='comma'>,</span><span class='kw'>nil</span><span class='comma'>,</span><span class='int'>9</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_sort_by'>sort_by</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_x'>x</span><span class='op'>|</span> <span class='id identifier rubyid_x'>x</span> <span class='op'>||</span> <span class='const'>Sorting</span><span class='op'>::</span><span class='const'>Bigger</span> <span class='rbrace'>}</span> <span class='comment'># Sorting::Smaller is available too
</span></code></pre>

<p>Take a look at <a href="file.examples.html" title="examples">examples</a> for more examples.</p>

<h2>Links</h2>

<ul>
<li><a href="http://rdoc.info/github/apeiros/sorting/">Online API Documentation</a></li>
<li><a href="https://github.com/apeiros/sorting">Public Repository</a></li>
<li><a href="https://github.com/apeiros/sorting/issues">Bug Reporting</a></li>
<li><a href="https://rubygems.org/gems/sorting">RubyGems Site</a></li>
</ul>

<h2>License</h2>

<p>You can use this code under the <a href="file.LICENSE.html" title="BSD-2-Clause License">BSD-2-Clause License</a>, free of charge.
If you need a different license, please ask the author.</p>
</div></div>

    <div id="footer">
  Generated on Sat Feb 23 14:24:55 2013 by
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.8.4.1 (ruby-1.9.3).
</div>

  </body>
</html>